package com.power.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.power.domain.Order;
import com.power.model.OrderConfirmParam;
import com.power.model.Result;
import com.power.service.OrderService;
import com.power.vo.OrderStatusCount;
import com.power.vo.OrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 微信小程序订单接口
 * @Author dingchunlin
 * @Date 2024/07/21 12:30
 * @Version 1.0.0
 */
@Api(tags = "微信小程序订单接口管理")
@RestController
@RequestMapping("/p/myOrder")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 查询会员订单各状态数量
     * @return 订单状态数量
     */
    @ApiOperation(value = "查询会员订单各状态数量")
    @GetMapping("/orderCount")
    public Result<OrderStatusCount> loadMemberOrderStatusCount() {
        OrderStatusCount orderStatusCount = orderService.queryMemberOrderStatusCount();
        return Result.success(orderStatusCount);
    }

    /**
     * 分页查询会员订单列表
     * @param current 当前页
     * @param size 每页数量
     * @param status 订单状态
     * @return 会员订单列表
     */
    @ApiOperation(value = "分页查询会员订单列表")
    @GetMapping("/myOrder")
    public Result<Page<Order>> loadMemberOrderPage(@RequestParam Long current,
                                                   @RequestParam Long size,
                                                    @RequestParam Integer status) {
        Page<Order> orderPage = orderService.queryMemberOrderPage(current, size, status);
        return Result.success(orderPage);
    }

    /**
     * 根据订单编号查询订单详情
     * @param orderNumber 订单编号
     * @return 订单详情
     */
    @ApiOperation(value = "根据订单编号查询订单详情")
    @GetMapping("/orderDetail")
    public Result<Order> loadMemberOrderDetail(@RequestParam String orderNumber) {
        Order order = orderService.queryMemberOrderDetailByOrderNumber(orderNumber);
        return Result.success(order);
    }

    /**
     * 会员确认收货
     * @param orderNumber 订单编号
     * @return 处理结果
     */
    @ApiOperation(value = "会员确认收货")
    @PutMapping("/receipt/{orderNumber}")
    public Result<String> receiptMemberOrder(@PathVariable String orderNumber) {
        Boolean result = orderService.receiptMemberOrder(orderNumber);
        return Result.handle(result);
    }

    /**
     * 删除会员订单
     * @param orderNumber 订单号
     * @return 是否成功
     */
    @ApiOperation(value = "删除会员订单")
    @DeleteMapping("/{orderNumber}")
    public Result<String> removeMemberOrder(@PathVariable String orderNumber) {
        Boolean result = orderService.removeMemberOrder(orderNumber);
        return Result.handle(result);
    }

    /**
     * 查询会员确认订单页面数据
     * @param orderConfirmParam 订单确认参数
     * @return 订单确认页面数据
     */
    @ApiOperation(value = "查询会员确认订单页面数据")
    @PostMapping("/confirm")
    public Result<OrderVo> loadMemberOrderConfirmVo(@RequestBody OrderConfirmParam orderConfirmParam) {
        OrderVo orderVo = orderService.queryMemberOrderConfirmVo(orderConfirmParam);
        return Result.success(orderVo);
    }
}
